<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>概念板块</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">			 
			.fixedBox{					
			white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
			width: 10px;     
			height: 10px;				
			}			
		</style>
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script>
			window.onload = function() {
			getSource();
			changeStyle();
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource();					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","15:15")						
				},
				60000);
			})
			
			function changeStyle() {
				var obj = document.getElementById("towrite");	
				obj.style.left= "0px"; 				
				obj.style.width= "520px";
				obj.style.border="none";		
				
				var obj1 = document.getElementById("towrite1");									
				obj1.style.width= "260px";	//左侧宽度
				obj1.style.fontSize="12px";	//左侧字体		
				
				var obj2 = document.getElementById("towrite2");
				obj2.style.left= "250px";   //右侧左边位置
				obj2.style.width= "250px";  //右侧宽度
				obj2.style.fontSize="12px";	//右侧字体	
							
			}	

			function createXmlHttp() {
				if (window.XMLHttpRequest) {
				xmlHttp1 = new XMLHttpRequest();
				xmlHttp2 = new XMLHttpRequest();
				} else {
				xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");
				xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
			
			function changeCss(obj,id){				
				var alist = document.getElementById(id).getElementsByTagName("a");					
				for(var i = 0; i < alist.length; i++){				
					if(alist[i] == undefined){
						break;
					}
					alist[i].style.color = "#d2d2d3"; //给所有a标签赋原色
				}
				obj.style.color = "#00FFFF"; //令当前标签高亮				
			}
			
			function getSource() {	    							
				var url1 = "https://apphq.longhuvip.com/w1/api/index.php?Order=1&a=RealRankingInfo&st=10&apiv=w21&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=5&"; 
				createXmlHttp();				
				xmlHttp1.onreadystatechange = writeSource;
				xmlHttp1.open("GET", url1, true);
				xmlHttp1.send(null);				
			}
			
			
			function writeSource() { 
				if (xmlHttp1.readyState == 4) {         
				var data1 = xmlHttp1.responseText	
				
				data1 = data1.replace(/ /g,"").match(/(\S*)\]\],\"/)[1] + ']]';	
				data1 = data1.replace(/(\[\").*?(?=\])/g,function(word){ str = word.match(/\[(\S*)/)[1]; return '{"code":' + str.split(',')[0] + ',"name":' + str.split(',')[1] + ',"qd":' + str.split(',')[2] + ',"zf":' + str.split(',')[3];});
				data1 = data1.replace(/\],\{/g,"},{").replace(/\]\]/g,"}]}");				
				
				//document.write(data2);
				var transform_aa1 = [           
				{"tag":"p", children:function(){return(json2html.transform(this.list, transform_bb1));}}
				];
				
				var transform_bb1= 
				//{"tag":"ul", children:[
				{"tag":"p", children:[											
				{"tag": "li", "html":"<a href='javascript:void(0);' onclick='update(\"${code}\"+\"#\"+\"${name}\");'>${name}&nbsp;&nbsp;强度：${qd} &nbsp;&nbsp;涨幅：${zf}% </a>"}, 											
				]};  
				
				var html1 = json2html.transform(data1, transform_aa1);		
				div1 = document.getElementById('towrite1');
				div1.innerHTML = '<h2>概念板块</h2>' + html1;
				$("div a:first").click();					
				}
			}
			
			function update(ss) {
				//alert(ss);
				var dms=ss.split('#');
				dm = dms[0];
				bk = dms[1];
				div2 = document.getElementById('towrite2');				
				div2.innerHTML = '<h3>' + bk + '</h3>';				
				var url2 = "https://apphq.longhuvip.com/w1/api/index.php?Order=1&st=30&a=ZhiShuStockList_W8&c=ZhiShuRanking&PhoneOSNew=1&old=1&apiv=w21&Type=6&PlateID=" + dm + "&"; 								
				createXmlHttp();
				xmlHttp2.onreadystatechange = writeSource2;				
				xmlHttp2.open("GET", url2, true);
				xmlHttp2.send(null);				
			}
			
			function writeSource2() { 			
				if (xmlHttp2.readyState == 4) {                  	
				var data2 = xmlHttp2.responseText
				
				data2 = data2.replace(/ /g,"").match(/(\S*)\]\],\"/)[1] + ']]';	
				data2 = data2.replace(/(\[\").*?(?=\])/g,function(word){ str = word.match(/\[(\S*)/)[1]; return '{"code":' + str.split(',')[0] + ',"name":' + str.split(',')[1]+',"zf":'+str.split(',')[6];});
				data2 = data2.replace(/\],\{/g,"},{").replace(/\]\]/g,"}]}");				
				//document.write(data2);
				
				var transform_aa2 = [           
				{"tag":"p", children:function(){return(json2html.transform(this.list, transform_bb2));}}
				];
				
				var transform_bb2= 
				//{"tag":"p", children:[
				{"tag":"p", children:[							
				{"tag": "li", "html":"<a href='http://www.treeid/code_${code}' onclick='changeCss(this,\"towrite2\")'>${code} ${name}&nbsp;&nbsp;涨幅：${zf}%</a>"}, 							
				]}; 
				
				
				var html2 = json2html.transform(data2, transform_aa2);		
				div2 = document.getElementById('towrite2');
				div2.innerHTML = div2.innerHTML + html2;
				//div2.innerHTML = '<h2>板块个股</h2>' + html2;				
				}
			}
		</script>
	</head>
	<body>
		<div id="towrite" class="fixedBox">
			<div id="towrite1" ></div>		
			<div id="towrite2" class="fixedBox" ></div>
		</div>
	</body>
</html>